#ifndef STATEREQUEST_H_
#define STATEREQUEST_H_

#include "scHeader.h"
#include "StateEngine.h"

namespace sybilpm
{

/**
 * The state engine specific to a single http requst.
 */
class StateRequest: public StateEngine
{
	Q_OBJECT
signals:
	void stateSuccessSig(unsigned long transId);
	void stateFailedSig(unsigned long transId);
public:
	StateRequest(unsigned long transId);
	virtual ~StateRequest();
	inline int CONNECT() const {return stConnect;}
	inline int SEND() const {return stSend;}
	inline int REC_HEAD() const {return stRecHead;}
	inline int REC_BODY() const {return stRecBody;}
	inline int SUCCESS() const {return stSuccess;}
	inline int FAILED() const {return stFailed;}
	inline int TEARDOWN() const {return stTeardown;}
	inline bool isConnect() const {return state==stConnect;}
	inline bool isSend() const {return state==stSend;}
	inline bool isRecHead() const {return state==stRecHead;}
	inline bool isRecBody() const {return state==stRecBody;}
	inline bool isSuccess() const {return state==stSuccess;}
	inline bool isFailed() const {return state==stFailed;}
	inline bool isTeardown() const {return state==stTeardown;}
	int conditionalTransition(int targetState);
	//int finishedTransition(bool headerOnly);

private:
	int stConnect, stSend, stRecHead, stRecBody, stSuccess, stFailed, stTeardown;
	int transSucSuc, transBodySuc;
	unsigned long id;
private slots:
	void notifySl();
};

} // namespace sybilpm

#endif /* STATEREQUEST_H_ */
